// component/house.js
import ajax from '../../utils/index'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item: Object,
    operation: Boolean,
    isAudit: Boolean,
    state: String,
    type: String
  },

  /**
   * 组件的初始数据
   */
  data: {
    checkStatus: ['审核中', '审核通过', '未通过'],
    rentStatusArr: ['未出租', '已出租', '正在出租'] // 租用状态：0未出租；1已出租（不能上架可以删除）；2正在出租
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 上架 / 下架 事件
     */
    putawayEvent() {
      const { item, checkStatus } = this.data
      if (item.checkStatus != 1) return ajax.showToast(checkStatus[item.checkStatus])
      this.triggerEvent('putaway')
    },
    /**
     * 审核事件
     */
    auditEvent() {
      wx.navigateTo({ url: `/pagesMine/pages/houseAudit/houseAudit?detailId=${this.data.item.id}` })
    },
    /**
     * 审核状态点击事件
     */
    checkStatusEvent() {
      const { item } = this.data
      if (item.checkStatus != 2) return
      wx.showModal({
        title: '提示',
        content: item.checkReason || '',
        showCancel: false
      })
    },
    houseEvent() {
      const { state, type, item } = this.data
      const url = state == 1 ? `/pagesMine/pages/housingResource/housingResource?detailId=${item.id}&houseId=${item.housingAssessId}&type=${type}` : `/pagesEnterprise/pages/houseDetail/houseDetail?houseId=${item.housingId}`
      wx.navigateTo({ url })
    },
    openMmap() {
      ajax.openMmap(this.data.item.housingLocation)
    },
    deleteEvent() {
      this.triggerEvent('delete', this.data.item)
    }
  }
})
